package org.cbg.panel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import com.tool.tcpimg.UIUtils;
import org.cbg.entity.Message;
import org.cbg.frame.TrslationMainJframe;
import org.come.until.CutButtonImage;

 

/**
 * 藏宝阁 我的藏宝阁 我的货物 Model
 * 
 * @author Administrator
 * 
 */

public class TraslationMyMessageModelJpanel extends JPanel {

    // 标题 名字 等级,勾选框，勾选
    private JLabel biaoti, mingzi, dengji, quanxuankuang, gouxuan;

    // 勾选状态（0勾选，1未勾选）
    private Integer gouxuanzhuangtai = 1;

    /**
     * 无参初始化
     */
    public TraslationMyMessageModelJpanel() {
        // TODO Auto-generated constructor stub

        this.setPreferredSize(new Dimension(304, 50));
        this.setOpaque(false);
        this.setLayout(null);


        biaoti = new JLabel("该商品已下架");
        biaoti.setBorder(null);
        biaoti.setBounds(40, 5, 150, 25);
        biaoti.setHorizontalAlignment(SwingConstants.CENTER);
        biaoti.setOpaque(false);
        biaoti.setForeground(Color.white);
        this.add(biaoti);

        mingzi = new JLabel("名字");
        mingzi.setBorder(null);
        mingzi.setBounds(315, 5, 60, 39);
        mingzi.setOpaque(false);
        mingzi.setForeground(Color.white);
        this.add(mingzi);

        dengji = new JLabel("120");
        dengji.setBorder(null);
        dengji.setBounds(450, 5, 60, 39);
        dengji.setOpaque(false);
        dengji.setForeground(Color.white);
        this.add(dengji);

        /**
         * 勾选状态
         */
        gouxuan = new JLabel();
        gouxuan.setBounds(13, 12, 15, 15);
        gouxuan.setOpaque(false);
        gouxuan.setIcon(null);
        gouxuan.setName("1");
        this.add(gouxuan);

        /**
         * 全选框 quanxuankuang
         */
        quanxuankuang = new JLabel();
        quanxuankuang.setBounds(13, 12, 17, 16);
        quanxuankuang.setOpaque(false);
        quanxuankuang.setIcon(CutButtonImage.getImage("inkImg/number/b4/gxk.png", 17, 16));
        this.add(quanxuankuang);

        /**
         * 勾选全选框
         */
        gouxuan.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                TraslationMyMessageJpanel traslationMyMessageJpanel = TrslationMainJframe.getTrslationMainJframe().getTrslationMainJpanel().getTranslationMainCardJpanel().getTraslationMyMessageJpanel();
                if ("1".equals(gouxuan.getName())) {
                    gouxuan.setIcon(CutButtonImage.getImage("skin/8100226/button/13.png", 15, 15));
                    gouxuan.setName("0");
                    TrslationMainJframe.getTrslationMainJframe().setGoodsGouxuangeshu(
                            TrslationMainJframe.getTrslationMainJframe().getGoodsGouxuangeshu() + 1);
                    if (TrslationMainJframe.getTrslationMainJframe().getGoodsGouxuangeshu() == 10) {
                        traslationMyMessageJpanel.getGouxuan()
                                .setIcon(CutButtonImage.getImage("skin/8100226/button/13.png", 15, 15));
                        traslationMyMessageJpanel.getGouxuan().setName("0");
                    }
                } else {
                    gouxuan.setIcon(null);
                    gouxuan.setName("1");
                    TrslationMainJframe.getTrslationMainJframe().setGoodsGouxuangeshu(
                            TrslationMainJframe.getTrslationMainJframe().getGoodsGouxuangeshu() - 1);
                    if (TrslationMainJframe.getTrslationMainJframe().getGoodsGouxuangeshu() != 10) {
                        traslationMyMessageJpanel.getGouxuan().setIcon(null);
                        traslationMyMessageJpanel.getGouxuan().setName("1");
                    }
                }

            }
        });

    }

    /**
     * 传参构造方法
     */
    public TraslationMyMessageModelJpanel(Message message) {
        // TODO Auto-generated constructor stub

        this.setPreferredSize(new Dimension(304, 50));
        this.setOpaque(false);
        this.setLayout(null);

        biaoti = new JLabel();
        biaoti.setBorder(null);
        biaoti.setBounds(140, 5, 150, 25);
        biaoti.setHorizontalAlignment(SwingConstants.CENTER);
        biaoti.setOpaque(false);
        biaoti.setForeground(UIUtils.COLOR_cbg6);
        this.add(biaoti);

        mingzi = new JLabel("系统提示");
        mingzi.setBorder(null);
        mingzi.setBounds(490, 5, 60, 39);
        mingzi.setOpaque(false);
        mingzi.setForeground(UIUtils.COLOR_cbg6);
        this.add(mingzi);

        dengji = new JLabel("120");
        dengji.setBorder(null);
        dengji.setBounds(600, 5, 150, 39);
        dengji.setOpaque(false);
        dengji.setForeground(UIUtils.COLOR_cbg6);
        this.add(dengji);

        /**
         * 添加数据
         */
        biaoti.setName(message.getMesid().toString());
        biaoti.setText(message.getMescontent());
        // mingzi.setText();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        dengji.setText(sdf.format(message.getGettime()));

        /**
         * 勾选状态
         */
        gouxuan = new JLabel();
        gouxuan.setBounds(13, 12, 15, 15);
        gouxuan.setOpaque(false);
        gouxuan.setIcon(null);
        gouxuan.setName("1");
        this.add(gouxuan);

        /**
         * 全选框 quanxuankuang
         */
        quanxuankuang = new JLabel();
        quanxuankuang.setBounds(13, 12, 17, 16);
        quanxuankuang.setOpaque(false);
        quanxuankuang.setIcon(CutButtonImage.getImage("inkImg/number/b4/gxk.png", 17, 16));
        this.add(quanxuankuang);

        /**
         * 勾选全选框
         */
        gouxuan.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                TraslationMyMessageJpanel traslationMyMessageJpanel = TrslationMainJframe.getTrslationMainJframe().getTrslationMainJpanel().getTranslationMainCardJpanel().getTraslationMyMessageJpanel();
                if ("1".equals(gouxuan.getName())) {
                    gouxuan.setIcon(CutButtonImage.getImage("skin/8100226/button/13.png", 15, 15));
                    gouxuan.setName("0");
                    TrslationMainJframe.getTrslationMainJframe().setXiaoxiGouxuangeshu(
                            TrslationMainJframe.getTrslationMainJframe().getXiaoxiGouxuangeshu() + 1);
                    if (TrslationMainJframe.getTrslationMainJframe().getGoodsGouxuangeshu() == TrslationMainJframe
                            .getTrslationMainJframe().getXiaoxiGeshuMax()) {
                        traslationMyMessageJpanel.getGouxuan()
                                .setIcon(CutButtonImage.getImage("skin/8100226/button/13.png", 15, 15));
                        traslationMyMessageJpanel.getGouxuan().setName("0");
                    }
                } else {
                    gouxuan.setIcon(null);
                    gouxuan.setName("1");
                    TrslationMainJframe.getTrslationMainJframe().setXiaoxiGouxuangeshu(
                            TrslationMainJframe.getTrslationMainJframe().getXiaoxiGouxuangeshu() - 1);
                    if (TrslationMainJframe.getTrslationMainJframe().getXiaoxiGouxuangeshu() != TrslationMainJframe
                            .getTrslationMainJframe().getXiaoxiGeshuMax()) {
                        traslationMyMessageJpanel.getGouxuan().setIcon(null);
                        traslationMyMessageJpanel.getGouxuan().setName("1");
                    }
                }

            }
        });

    }

    public JLabel getBiaoti() {
        return biaoti;
    }

    public void setBiaoti(JLabel biaoti) {
        this.biaoti = biaoti;
    }

    public JLabel getMingzi() {
        return mingzi;
    }

    public void setMingzi(JLabel mingzi) {
        this.mingzi = mingzi;
    }

    public JLabel getDengji() {
        return dengji;
    }

    public void setDengji(JLabel dengji) {
        this.dengji = dengji;
    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        if (icon == null) {
            icon = CutButtonImage.getImage("inkImg/old/1/Z1001.png", 740, 2);
        }
        g.drawImage(icon.getImage(), 0, 58, 740, 2, this);


    }

}
